/*
	File:	video/Texture.hpp
	Date:	2013-06-01
	Author:	Asteroth
*/


#ifndef __ZEN_TEXTURE_HPP__
#define __ZEN_TEXTURE_HPP__

#include <string.h>
#include <ptr.hpp>

#include "../gl.hpp"

#include "Pixmap.hpp"

namespace zen {

	namespace video {


		class Texture {

		public:

			Texture(GLuint handle = 0): handle(handle), type(GL_TEXTURE_2D) { }
			Texture(GLuint handle, const std::string &fileName): handle(handle), fileName(fileName), type(GL_TEXTURE_2D) { }
			Texture(GLenum type, GLuint handle): type(type), handle(handle) { }
			Texture(GLenum type, GLuint handle, const std::string &fileName): type(type), handle(handle), fileName(fileName) { }
			~Texture();
			
			/**
			* Returns the texture handle, does not throw null pointer exception.
			*/
			GLenum getType() const { return this == nullptr ? 0 : type; }

			/**
			* Returns the texture handle, does not throw null pointer exception.
			*/
			GLuint getHandle() const { return this == nullptr ? 0 : handle; }
			
			/**
			* Returns true if it's a valid texture, does not throw null pointer exception.
			*/
			bool empty() const { return this == nullptr || handle == 0; }

			std::string getFileName() const { return fileName; }
			void setFileName(const std::string &fileName) { this->fileName = fileName; }
			
			/**
			* Activates this texture which will be used until it will be deactivated or another texture will be activated.
			*/
			void activate(GLenum unit = GL_TEXTURE0) const;

			
		private:

			GLenum type;
			GLuint handle;
			std::string fileName;

			// Textures must not be replicated.
			Texture(const Texture&);
			Texture& operator = (const Texture&);

		};


		typedef ptr(Texture) PTexture;


	} // namespace video

} // namespace zen

#endif // __ZEN_TEXTURE_HPP__
